<script setup lang="ts">
import { WarningFilled } from '@element-plus/icons-vue'
import { ElTree } from 'element-plus'
import { PAGING, TEMPORARY } from '@/constant'
// ------------------use------------------
// #region
const { vLoading, withLoading } = useDefineLoading()
const [isDetailDialog, setIsDetailDialog]
  = useState<boolean>(false)
const [tableData, setTableData] = useState<any[]>([])
// #endregion
// ------------------静态变量------------------
// #region
const treeData = TEMPORARY.productionProcesses
// #endregion
// ------------------动态变量------------------
// #region

// #endregion
// ------------------ref-----------
// #region
const detailContentType = ref<string>('图表')
const treeRef = ref<InstanceType<typeof ElTree>>()
const filterInputValue = ref<string>('')
// #endregion
// ------------------reactive------
// #region

// #endregion
// ------------------computed------
// #region

// #endregion
// ------------------生命周期------------------
// #region
onMounted(() => {
  getTableData()
})
// #endregion
// ------------------内置方法---------------------
// #region
watch(
  () => filterInputValue.value,
  (value: string) => {
    treeRef.value!.filter(value)
  },
)
// #endregion
// ------------------方法---------------------
// #region
async function getTableData() {
  await withLoading(sleep)(1000)
  setTableData(Array.from({ length: 20 }).fill(0))
}
function filterNode(value: string, data: any) {
  if (!value)
    return true
  return data.label.includes(value)
}
function reset() {
  getTableData()
}
function search() {
  getTableData()
}
function showDetailDialog() {
  setIsDetailDialog(true)
}
// #endregion
</script>

<template>
  <div
    class="padding-sm align-center box-border flex gap-sm container"
  >
    <div
      class="container-left height-fill flex-incompressible padding-sm flex-direction box-border flex gap-xs"
    >
      <el-input
        v-model="filterInputValue"
        placeholder="全部"
        clearable
        class="flex-incompressible free"
      />
      <b-scrollbar class="flex-fillRemaining">
        <ElTree
          ref="treeRef"
          highlight-current
          default-expand-all
          :data="treeData"
          :filter-node-method="filterNode"
        />
      </b-scrollbar>
    </div>
    <div
      class="container-right height-fill flex-direction overflow flex-fillRemaining flex align-end"
    >
      <el-form
        inline
        label-width="40px"
        label-position="left"
        class="flex-incompressible width-fill"
      >
        <el-form-item label="指标">
          <el-select>
            <el-option disabled label="请选择" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="周期">
          <el-date-picker
            type="monthrange"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </el-form-item>
        <el-form-item>
          <el-button plain @click="reset">
            重置
          </el-button>
          <el-button type="primary" @click="search">
            查询
          </el-button>
          <el-button type="primary">
            导出
          </el-button>
        </el-form-item>
      </el-form>
      <p
        class="margin-0 margin-bottom-xs width-fill container-tip flex-incompressible"
        style=""
      >
        没有采集
        <el-icon class="vertical-align-middle text-black">
          <WarningFilled />
        </el-icon>
        超出范围
        <el-icon class="vertical-align-middle text-red">
          <WarningFilled />
        </el-icon>
        没有上报
        <el-icon class="vertical-align-middle text-yellow">
          <WarningFilled />
        </el-icon>
      </p>
      <el-table
        v-loading
        :data="tableData"
        class="width-fill flex-fillRemaining"
      >
        <el-table-column
          type="index"
          label="序号"
          width="80"
        />
        <el-table-column label="指标名称" width="200">
          <el-button
            link
            type="primary"
            @click="showDetailDialog"
          >
            全厂-一次能源-其它原煤-购进已消费
          </el-button>
        </el-table-column>
        <el-table-column label="指标范围">
          全厂
        </el-table-column>
        <el-table-column label="时间">
          2023-12
        </el-table-column>
        <el-table-column label="指标值">
          0
          <el-icon class="text-yellow">
            <WarningFilled />
          </el-icon>
        </el-table-column>
        <el-table-column label="计量单位">
          吨
        </el-table-column>
      </el-table>
      <el-pagination
        hide-on-single-page
        :page-sizes="PAGING.PAGE_SIZES"
        layout="total, sizes, prev, pager, next, jumper"
        :total="20"
        background
        class="flex-incompressible margin-top-sm"
      />
    </div>
    <!-- 详情 -->
    <el-dialog
      v-model="isDetailDialog"
      title="全厂-一次能源-其它原煤-购进已消费"
      width="1200"
      append-to-body
    >
      <div
        class="align-center margin-bottom-xs flex justify-between"
        style="margin-top: -10px"
      >
        <div>
          <el-date-picker
            type="daterange"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
          <el-button
            plain
            class="margin-left-sm"
            @click="reset"
          >
            重置
          </el-button>
          <el-button type="primary" @click="search">
            查询
          </el-button>
        </div>
        <el-radio-group v-model="detailContentType">
          <el-radio-button label="图表" />
          <el-radio-button label="表格" />
        </el-radio-group>
      </div>
      <div
        v-loading
        style="height: 50vh; margin-bottom: -15px"
      >
        <el-table
          v-if="detailContentType === '表格'"
          :data="[]"
          class="flex-fillRemaining width-fill height-fill"
        >
          <el-table-column
            fixed
            type="index"
            label="序号"
            width="80"
          />
          <el-table-column label="时间">
            <el-button type="primary" link />
          </el-table-column>
          <el-table-column label="数值">
            {{ '---' }}
          </el-table-column>
        </el-table>
        <ViewChartLine v-else />
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="setIsDetailDialog(false)">
            关闭
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<style lang="scss" scoped>
.container {
  --container-left-w: 240px;
  &-left {
    width: var(--container-left-w);
    border: 1px solid var(--el-border-color-light);
    border-radius: 4px;
    transition: all var(--motion-bezier) 0.3s;
    &:hover {
      box-shadow: 0 8px 32px #0000000d;
    }
  }
}
//------------------组件样式------------------
//-------------样式穿透-------------
</style>
